package cn.itsource.hrm.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static cn.itsource.hrm.constants.MQConstants.*;

@Configuration
public class MQConfig {

    //定义交换机
    @Bean
    public Exchange exchangeNameDirect(){
        return ExchangeBuilder.directExchange(EXCHANGE_NAME_DIRECT).durable(true).build();
    }

    //定义邮件的队列Bean
    @Bean
    public Queue emailQueue(){
        return new Queue(QUEUE_NAME_EMAIL,true);
    }
    //定义短信的队列Bean
    @Bean
    public Queue smsQueue(){
        return new Queue(QUEUE_NAME_SMS,true);
    }
    //定义系统消息的队列Bean
    @Bean
    public Queue systemMessageQueue(){
        return new Queue(QUEUE_NAME_SYSTEM_MESSAGE,true);
    }

    //定义邮件的队列绑定到交换机
    @Bean
    public Binding smsQueueBinding(){
        return BindingBuilder.bind(smsQueue()).to(exchangeNameDirect()).with(ROUTINGKEY_MESSAGE_SMS).noargs();
    }
    @Bean
    public Binding emailQueueBinding(){
        return BindingBuilder.bind(emailQueue()).to(exchangeNameDirect()).with(ROUTINGKEY_MESSAGE_EMAIL).noargs();
    }
    @Bean
    public Binding systemMessageQueueBinding(){
        return BindingBuilder.bind(systemMessageQueue()).to(exchangeNameDirect()).with(ROUTINGKEY_MESSAGE_SYSTEM).noargs();
    }



}
